﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ITMAN.AssetMan_FRMs
{
    public partial class FRM_asset_bearbeiten : Form
    {
        public FRM_asset_bearbeiten()
        {
            InitializeComponent();
        }

        public static string asset_nr;

        private void build_DGV_row()
        {
            Klassen.CL_assetman assetman = new Klassen.CL_assetman();
            DGV_asset_aktuell.DataSource = assetman.get_assets_detail_to_datatable(asset_nr);
            DGV_asset_histroy.DataSource = assetman.get_asset_histroy(asset_nr);
            int counter = DGV_asset_aktuell.Columns.Count;
            for (int i = 0; i < counter; i++)
            {
                switch (DGV_asset_aktuell.Columns[i].HeaderText)
                {
                    case "Kategorie":
                        DataGridViewComboBoxCell combo_cell_kategorie = new DataGridViewComboBoxCell();
                        combo_cell_kategorie.AutoComplete = true;
                        List<string> lst_kat = assetman.get_kategorien();
                        for (int ii = 0; ii < lst_kat.Count; ii++)
                        {
                            combo_cell_kategorie.Items.Add(lst_kat[ii]);
                        }
                        DGV_asset_aktuell[i, 0] = combo_cell_kategorie;
                        break;
                    case "Status":
                        DataGridViewComboBoxCell combo_cell_status = new DataGridViewComboBoxCell();
                        combo_cell_status.AutoComplete = true;
                        List<string> lst_status = assetman.get_status();
                        for (int iii = 0; iii < lst_status.Count; iii++)
                        {
                            combo_cell_status.Items.Add(lst_status[iii]);
                        }
                        DGV_asset_aktuell[i, 0] = combo_cell_status;
                        break;
                    case "Standort":
                        DataGridViewComboBoxCell combo_cell_standort = new DataGridViewComboBoxCell();
                        combo_cell_standort.AutoComplete = true;
                        List<string> lst_standort = assetman.get_standorte();
                        for (int iiii = 0; iiii < lst_standort.Count; iiii++)
                        {
                            combo_cell_standort.Items.Add(lst_standort[iiii]);
                        }
                        DGV_asset_aktuell[i, 0] = combo_cell_standort;
                        break;
                    case "Ersteller":
                        DGV_asset_aktuell.Rows[0].Cells[i].ReadOnly = true;
                        break;
                    case "Erstelldatum":
                        DGV_asset_aktuell.Rows[0].Cells[i].ReadOnly = true;
                        break;
                    case "geändert_von":
                        DGV_asset_aktuell.Rows[0].Cells[i].ReadOnly = true;
                        break;
                    case "letzte_änderung":
                        DGV_asset_aktuell.Rows[0].Cells[i].ReadOnly = true;
                        break;
                }
            }
        }


        private void FRM_asset_bearbeiten_Load(object sender, EventArgs e)
        {
            build_DGV_row();
        }

        private void BTN_asset_anlegen_Click(object sender, EventArgs e)
        {
            Klassen.CL_assetman assetman = new Klassen.CL_assetman();
            if (DGV_asset_aktuell.SelectedCells.Count > 0)
            {
                int selectedrowindex = DGV_asset_aktuell.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow = DGV_asset_aktuell.Rows[selectedrowindex];
                assetman.update_asset(asset_nr, selectedRow);
            }
            DGV_asset_aktuell.Columns.Clear();
            DGV_asset_histroy.Columns.Clear();
            build_DGV_row();
        }
    }
}
